package com.wxb.note.run;

import com.wxb.note.catty.ActiveOne;
import com.wxb.note.catty.ICatty;
import com.wxb.note.constant.PriceType;
import com.wxb.note.model.Apple;
import com.wxb.note.model.BaseFruit;
import com.wxb.note.model.Strawberry;

import java.math.BigDecimal;
import java.util.Arrays;

public class AppTest {
    public static void main(String[] args) {
        BigDecimal totalPrice = null;
        // question1：
        BaseFruit apple = new Apple(getBigDecimal("8"),
                getBigDecimal("10"));
        BaseFruit strawberry = new Strawberry(getBigDecimal("13"),
                getBigDecimal("5"));
        totalPrice = BaseFruit.multiplePriceCount(Arrays.asList(
                apple.calculation(),
                strawberry.calculation()));
        // 不涉及打折，是整数
        System.out.println("question1 result:" + totalPrice.toBigInteger());

        //question2
        BaseFruit mango = new Strawberry(getBigDecimal("20"),
                getBigDecimal("5"));
        // 不涉及打折，是整数
        totalPrice = BaseFruit.multiplePriceCount(Arrays.asList(
                apple.calculation(),
                strawberry.calculation(),
                mango.calculation()));
        System.out.println("question2 result:" + totalPrice.toBigInteger());

        //question3
        strawberry = new Strawberry(getBigDecimal("13"),
                PriceType.HALF_A_KILOGRAM,
                getBigDecimal("5"),
                getBigDecimal("0.8"));
        totalPrice = BaseFruit.multiplePriceCount(Arrays.asList(
                apple.calculation(),
                strawberry.calculation(),
                mango.calculation()));
        System.out.println("question3 result:" + totalPrice.toString());

        // question 4
        ICatty activeOne = new ActiveOne();
        totalPrice = BaseFruit.multiplePriceCount(Arrays.asList(
                apple.calculation(),
                strawberry.calculation(),
                mango.calculation()),
                activeOne);
        System.out.println("question4 result:" + totalPrice.toString());
    }

    /**
     * 使用字符串来保证精度
     * @param number
     * @return
     */
    private static BigDecimal getBigDecimal(String number) {
        return new BigDecimal(number);
    }
}
